﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace BaMusaSoft.RPS.DataModel.Repositories
{
    /// <summary>
    /// Represent Claim Repostiory. Instantiate via UnitOfWork object.
    /// </summary>
    public sealed class ClaimsRepository:RepositoryBase<Claim>
    {
        internal ClaimsRepository(RpsEntities context) : base(context)
        {
        }

        #region Overrides of BaseRepository<Claim>

        /// <summary>
        /// Adds the specified entity to the repository.
        /// </summary>
        /// <param name="entity">The entity.</param>
        public override void Add(Claim entity)
        {
            if (entity == null) throw new ArgumentNullException("entity");
            Context.Claims.Add(entity);
        }

        /// <summary>
        /// Deletes the specified entity from the repository.
        /// </summary>
        /// <param name="entity">The entity.</param>
        public override void Delete(Claim entity)
        {
            if (entity == null) throw new ArgumentNullException("entity");
            Context.Claims.Remove(entity);
        }

        /// <summary>
        /// Gets the entity by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public override Claim GetById(object id)
        {
            if (id == null) throw new ArgumentNullException("id");
            return Context.Claims.Where(x => x.Id == (int) id).Single();
        }


        /// <summary>
        /// Query repository by specified filter.
        /// </summary>
        /// <param name="filter">The filter.</param>
        /// <returns></returns>
        public override IQueryable<Claim> Query(Expression<Func<Claim, bool>> filter)
        {
            if (filter == null) throw new ArgumentNullException("filter");
            return Context.Claims.Where(filter);
        }

        /// <summary>
        /// Gets all entities in the repository.
        /// </summary>
        /// <returns></returns>
        public override IList<Claim> GetAll()
        {
            return Context.Claims.ToList();
        }

        public override void Refresh()
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}